package sistemadeproyectos;

import javax.swing.ImageIcon;
import java.awt.Image;
import javax.swing.UIManager;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.*;

/**
 * @author Angel Rubio, 06-40263
 * @author Antonio Mundo, 06-39956
 * @author Giancarlo Nebiolo, 06-39965
 * @version 1.5
 */

public class AdministradorRed extends javax.swing.JFrame {

    private RepositorioServidor repoServ;
    private ChatServidor chatServ;
    
    /** Creates new form AdministradorRed */
    public AdministradorRed() {
        initComponents();
        jlblEncendidoRep.setIcon(ajustarImagen(System.getProperty("user.dir") + "\\src\\sistemadeproyectos\\images\\Rojo.jpg",jlblEncendidoRep.getWidth(),jlblEncendidoRep.getHeight()));
        jlblEncendidoChat.setIcon(ajustarImagen(System.getProperty("user.dir") + "\\src\\sistemadeproyectos\\images\\Rojo.jpg",jlblEncendidoChat.getWidth(),jlblEncendidoChat.getHeight()));
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(new java.awt.Point(d.width/3,d.height/3));
        this.setSize(50, 320);
    }

    private ImageIcon ajustarImagen(String ico, int ancho, int alto) {
        ImageIcon tmpIconAux = new ImageIcon(ico);
        //Escalar Imagen
        ImageIcon tmpIcon = new ImageIcon(tmpIconAux.getImage().getScaledInstance(ancho, alto, Image.SCALE_DEFAULT));
        return tmpIcon;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbtnServidorRepositorio = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jbtnServidorChat = new javax.swing.JButton();
        jbtnQuejas = new javax.swing.JButton();
        jbtnSalir = new javax.swing.JButton();
        jlblEncendidoRep = new javax.swing.JLabel();
        jlblEncendidoChat = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemadeproyectos.SistemadeproyectosApp.class).getContext().getResourceMap(AdministradorRed.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setMinimumSize(new java.awt.Dimension(532, 257));
        setName("Form"); // NOI18N
        setResizable(false);
        getContentPane().setLayout(null);

        jbtnServidorRepositorio.setText(resourceMap.getString("jbtnServidorRepositorio.text")); // NOI18N
        jbtnServidorRepositorio.setName("jbtnServidorRepositorio"); // NOI18N
        jbtnServidorRepositorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnServidorRepositorioActionPerformed(evt);
            }
        });
        getContentPane().add(jbtnServidorRepositorio);
        jbtnServidorRepositorio.setBounds(20, 80, 210, 30);

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(30, 20, 354, 31);

        jbtnServidorChat.setText(resourceMap.getString("jbtnServidorChat.text")); // NOI18N
        jbtnServidorChat.setName("jbtnServidorChat"); // NOI18N
        jbtnServidorChat.setPreferredSize(new java.awt.Dimension(193, 23));
        jbtnServidorChat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnServidorChatActionPerformed(evt);
            }
        });
        getContentPane().add(jbtnServidorChat);
        jbtnServidorChat.setBounds(20, 120, 210, 30);

        jbtnQuejas.setText(resourceMap.getString("jbtnQuejas.text")); // NOI18N
        jbtnQuejas.setName("jbtnQuejas"); // NOI18N
        jbtnQuejas.setPreferredSize(new java.awt.Dimension(193, 23));
        jbtnQuejas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnQuejasActionPerformed(evt);
            }
        });
        getContentPane().add(jbtnQuejas);
        jbtnQuejas.setBounds(20, 160, 210, 30);

        jbtnSalir.setText(resourceMap.getString("jbtnSalir.text")); // NOI18N
        jbtnSalir.setName("jbtnSalir"); // NOI18N
        jbtnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSalirActionPerformed(evt);
            }
        });
        getContentPane().add(jbtnSalir);
        jbtnSalir.setBounds(20, 210, 210, 30);

        jlblEncendidoRep.setText(resourceMap.getString("jlblEncendidoRep.text")); // NOI18N
        jlblEncendidoRep.setName("jlblEncendidoRep"); // NOI18N
        getContentPane().add(jlblEncendidoRep);
        jlblEncendidoRep.setBounds(240, 80, 34, 26);

        jlblEncendidoChat.setName("jlblEncendidoChat"); // NOI18N
        getContentPane().add(jlblEncendidoChat);
        jlblEncendidoChat.setBounds(240, 120, 34, 26);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnServidorRepositorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnServidorRepositorioActionPerformed
        // TODO add your handling code here: file:/192.168.1.100/
        if(jbtnServidorRepositorio.getText().equals("Encender Servidor de Repositorio")){
            repoServ = new RepositorioServidor();
            repoServ.start();
            jbtnServidorRepositorio.setText("Apagar Servidor de Repositorio");
            jlblEncendidoRep.setIcon(ajustarImagen(System.getProperty("user.dir") + "\\src\\sistemadeproyectos\\images\\Verde.jpg",jlblEncendidoRep.getWidth(),jlblEncendidoRep.getHeight()));
        }
        else if(jbtnServidorRepositorio.getText().equals("Apagar Servidor de Repositorio")){
            repoServ.cerrar();
            repoServ = null;
            System.gc();
            jbtnServidorRepositorio.setText("Encender Servidor de Repositorio");
            jlblEncendidoRep.setIcon(ajustarImagen(System.getProperty("user.dir") + "\\src\\sistemadeproyectos\\images\\Rojo.jpg",jlblEncendidoRep.getWidth(),jlblEncendidoRep.getHeight()));
        }
    }//GEN-LAST:event_jbtnServidorRepositorioActionPerformed

    private void jbtnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSalirActionPerformed
        // TODO add your handling code here:
        if(jbtnServidorRepositorio.getText().equals("Apagar Servidor de Repositorio")){
            repoServ.cerrar();
            repoServ = null;
            System.gc();
        }
        if(jbtnServidorChat.getText().equals("Apagar Servidor de Chat")){
            chatServ.cerrar();
            chatServ = null;
            System.gc();
        }
        System.exit(0);
    }//GEN-LAST:event_jbtnSalirActionPerformed

    private void jbtnServidorChatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnServidorChatActionPerformed
        // TODO add your handling code here:
        if(jbtnServidorChat.getText().equals("Encender Servidor de Chat")){
            chatServ = new ChatServidor();
            chatServ.start();
            jbtnServidorChat.setText("Apagar Servidor de Chat");
            jlblEncendidoChat.setIcon(ajustarImagen(System.getProperty("user.dir") + "\\src\\sistemadeproyectos\\images\\Verde.jpg",jlblEncendidoChat.getWidth(),jlblEncendidoChat.getHeight()));
        }
        else if(jbtnServidorChat.getText().equals("Apagar Servidor de Chat")){
            chatServ.cerrar();
            chatServ = null;
            System.gc();
            jbtnServidorChat.setText("Encender Servidor de Chat");
            jlblEncendidoChat.setIcon(ajustarImagen(System.getProperty("user.dir") + "\\src\\sistemadeproyectos\\images\\Rojo.jpg",jlblEncendidoChat.getWidth(),jlblEncendidoChat.getHeight()));
        }
    }//GEN-LAST:event_jbtnServidorChatActionPerformed

    private void jbtnQuejasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnQuejasActionPerformed
        // TODO add your handling code here:
        try{
            VerReclamos ver = new VerReclamos();
            ver.setVisible(true);
        }
        catch(SQLException se){}
        
    }//GEN-LAST:event_jbtnQuejasActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try{
                    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
                    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
                    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
                    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");                            
                    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                }
                catch(Exception e){
                    System.out.println("No disponibke");
                }
                new AdministradorRed().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton jbtnQuejas;
    private javax.swing.JButton jbtnSalir;
    private javax.swing.JButton jbtnServidorChat;
    private javax.swing.JButton jbtnServidorRepositorio;
    private javax.swing.JLabel jlblEncendidoChat;
    private javax.swing.JLabel jlblEncendidoRep;
    // End of variables declaration//GEN-END:variables
}